package utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.android.volley.VolleyError;

import Constant.Constance;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import model.HxStatus;
import model.HxUser;
import volley.VolleyListener;

public class SetUtils {
	/**
	 * 登录状态
	 * @param context
	 * @param checked
	 */
	public  static void saveLoginState(Context context,boolean logined) {
        SharedPreferences sp = context.getSharedPreferences("Login", Context.MODE_PRIVATE);
        sp.edit().putBoolean("Login", logined).commit();
	}
	public static boolean islogined(Context context) {
		SharedPreferences sp = context.getSharedPreferences("Login", Context.MODE_PRIVATE);
		boolean logined = sp.getBoolean("Login", false);
		return logined;
	}
	/**
	 * 保存用户ID
	 * @param context
	 * @param checked
	 */
	public  static void saveUserID(Context context,int UserId) {
		SharedPreferences sp = context.getSharedPreferences("UserID", Context.MODE_PRIVATE);
		sp.edit().putInt("UserID", UserId).commit();
	}
	public static int  GetUserId(Context context) {
		SharedPreferences sp = context.getSharedPreferences("UserID", Context.MODE_PRIVATE);
		return sp.getInt("UserID",0);
	}
	/**
	 * 保存极光用户ID
	 * @param context
	 * @param checked
	 */
	public  static void saveJGID(Context context,String UserId) {
		SharedPreferences sp = context.getSharedPreferences("JGId", Context.MODE_PRIVATE);
		sp.edit().putString("JGId", UserId).commit();
	}
	public static String  GetJGId(Context context) {
		SharedPreferences sp = context.getSharedPreferences("JGId", Context.MODE_PRIVATE);
		return sp.getString("JGId",null);
	}
	/**
	 * 保存用户名
	 * @param context
	 * @param checked
	 */
	public  static void saveUserName(Context context,String UserName) {
		SharedPreferences sp = context.getSharedPreferences("UserName", Context.MODE_PRIVATE);
		sp.edit().putString("UserName", UserName).commit();
	}
	public static String  GetUserName(Context context) {
		SharedPreferences sp = context.getSharedPreferences("UserName", Context.MODE_PRIVATE);
		return sp.getString("UserName", null);
	}
	/**
	 * 保存手机号码
	 * @param context
	 * @param checked
	 */
	public  static void saveUserPhone(Context context,String UserPhone) {
		SharedPreferences sp = context.getSharedPreferences("UserPhone", Context.MODE_PRIVATE);
		sp.edit().putString("UserPhone", UserPhone).commit();
	}
	public static String  GetUserPhone(Context context) {
		SharedPreferences sp = context.getSharedPreferences("UserPhone", Context.MODE_PRIVATE);
		return sp.getString("UserPhone", null);
	}
	/**
	 * 保存手机号码
	 * @param context
	 * @param checked
	 */
	public  static void saveUserNickName(Context context,String UserNickName) {
		SharedPreferences sp = context.getSharedPreferences("UserNickName", Context.MODE_PRIVATE);
		sp.edit().putString("UserNickName", UserNickName).commit();
	}
	public static String  GetUserNickName(Context context) {
		SharedPreferences sp = context.getSharedPreferences("UserNickName", Context.MODE_PRIVATE);
		return sp.getString("UserNickName", null);
	}
	/**
	 * 保存社区分类ID
	 * @param context
	 * @param checked
	 */
	public  static void saveCircleID(Context context,int CircleID) {
		SharedPreferences sp = context.getSharedPreferences("CircleID", Context.MODE_PRIVATE);
		sp.edit().putInt("CircleID", CircleID).commit();
	}
	public static int  GetCircleID(Context context) {
		SharedPreferences sp = context.getSharedPreferences("CircleID", Context.MODE_PRIVATE);
		return sp.getInt("CircleID", 0);
	}
	/**
	 * 保存用户图片
	 * @param context
	 * @param checked
	 */
	public  static void saveUserIcon(Context context,String UserIcon) {
		SharedPreferences sp = context.getSharedPreferences("UserIcon", Context.MODE_PRIVATE);
		sp.edit().putString("UserIcon", UserIcon).commit();
	}
	public static String  GetUserIcon(Context context) {
		SharedPreferences sp = context.getSharedPreferences("UserIcon", Context.MODE_PRIVATE);
		return sp.getString("UserIcon", null);
	}
	/**
	 * 消息推送状态
	 * @param context
	 * @param checked
	 */
	public  static void SaveMessageState(Context context,boolean isend) {
		SharedPreferences sp = context.getSharedPreferences("Message", Context.MODE_PRIVATE);
		sp.edit().putBoolean("Message", isend).commit();
	}
	public static boolean isSendMsg(Context context) {
		SharedPreferences sp = context.getSharedPreferences("Message", Context.MODE_PRIVATE);
		boolean isend = sp.getBoolean("Message", false);
		return isend;
	}
	
	/**
	 * 无图模式
	 * @param context
	 * @param checked
	 */
	public  static void saveNoImage(Context context,boolean checked) {
        SharedPreferences sp = context.getSharedPreferences("NoImage", Context.MODE_PRIVATE);
        sp.edit().putBoolean("NoImage", checked).commit();
	}
	public static boolean isNoImage(Context context) {
		SharedPreferences sp = context.getSharedPreferences("NoImage", Context.MODE_PRIVATE);
		boolean isNoImage = sp.getBoolean("NoImage", false);
		return isNoImage;
	}
	
	/**
	 * 转换时间
	 * @param date
	 * @return
	 */
	@SuppressLint("SimpleDateFormat")
	public static long  ChangDate(String date) { 
		long time = 0;
		//设定时间的模板 
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		//得到指定模范的时间
		try {
			time = sdf.parse(date).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return time;
	} 
	/**
	 * 获取当前的时间
	 * @return
	 */
	public static String  getTime(){
		 Date dt=new Date();
	     SimpleDateFormat matter1=new SimpleDateFormat("yyyyMMddHHmmssms");
	     return matter1.format(dt);
	}
	private static  String HxUser;
	public static String getHxUser(Context context,int UserId){
		HTTPUtils.get(context, Constance.URL.USER+"/"+UserId+"/easemob", new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				HxStatus hxStatus = GsonUtils.parseJSON(arg0, HxStatus.class);
				if(hxStatus.getStatus().equals(Constance.STATUS_TYPE.SUCCESS)){
					HxUser= hxStatus.getResult().getEasemobName();
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				
			}
		});
		return HxUser;
	}
}
